web/src/pages/[...listing].astro

507 lines · 14367 bytes

  1---
  2import Layout from '@layouts/Layout.astro';
  3import ListingHero from '@components/things/ListingHero.astro';
  4import ServiceList from '@components/things/ServiceList.astro';
  5import Comments from '@components/things/Comments.svelte';
  6import GitHubDetailedInfo from '@components/things/GitHubDetailedInfo.astro';
  7import SecurityDetailedInfo from '@components/things/SecurityDetailedInfo.astro';
  8import PrivacyPolicyDetails from '@components/things/PrivacyPolicyDetails.astro';
  9import WebsiteDetailedInfo from '@components/things/WebsiteDetailedInfo.astro';
 10import DockerDetailedInfo from '@components/things/DockerDetailedInfo.astro';
 11import IosAppDetailedInfo from '@components/things/IosAppDetailedInfo.astro';
 12import AndroidAppDetailedInfo from '@components/things/AndroidDetailedInfo.astro';
 13import DiscordDetailedInfo from '@components/things/DiscordDetailedInfo.astro';
 14import RedditDetailedInfo from '@components/things/RedditDetailedInfo.astro';
 15import SocialShare from '@components/form/Social.astro';
 16import DataActions from '@components/things/DataActions.svelte';
 17import type { AwesomePrivacy, Section, Service } from '../types/Service';
 18import { fetchData, slugify } from '@utils/fetch-data';
 19import { codebergUrl } from '@utils/parse-markdown';
 20import { fetchChangelog } from '@utils/fetch-changelog';
 21import { fetchGitHubStats } from '@utils/fetch-repo-info';
 22import { fetchSecurityReport } from '@utils/fetch-security-info';
 23import { fetchTosdrPrivacy } from '@utils/fetch-privacy-policy';
 24import { fetchWebsiteInfo } from '@utils/fetch-website-info';
 25import { fetchDockerData } from '@utils/fetch-docker-instructions';
 26import { fetchIosInfo } from '@utils/fetch-ios-info';
 27import { fetchAndroidInfo } from '@utils/fetch-android-info';
 28import { fetchPlexusInfo } from '@utils/fetch-plexus-info';
 29import { fetchDiscordInfo } from '@utils/fetch-discord-info';
 30import { fetchRedditInfo } from '@utils/fetch-reddit-info';
 31import { site } from '@utils/config';
 32import { apiBase, serviceSlug } from '@utils/api-config';
 33import Button from '@components/form/Button.astro';
 34
 35interface Props extends Service {
 36	slug: string;
 37	parentSection: Section;
 38	categoryName: string;
 39}
 40
 41const {
 42	name,
 43	description,
 44	url,
 45	github,
 46	codeberg,
 47	git,
 48	tosdrId,
 49	discordInvite,
 50	subreddit,
 51	iosApp,
 52	androidApp,
 53	parentSection,
 54	categoryName,
 55} = Astro.props;
 56
 57const makeKeyWordTag = () => {
 58	const keywords = [
 59		`open source ${parentSection.name}`,
 60		`${parentSection.name} comparison`,
 61		...(parentSection.alternativeTo || []).map(
 62			(alt: string) => `${alt} alternative`,
 63		),
 64		...(parentSection.services || []).map((serv: Service) => `${serv.name} vs`),
 65		'private',
 66		'ad free',
 67		'encrypted',
 68		'open source software',
 69		'privacy respecting apps',
 70		'free tools',
 71	];
 72	return keywords.join(', ');
 73};
 74
 75const makePageTitle = () => {
 76	return `${name} | ${parentSection.name} | ${categoryName} | Awesome Privacy`;
 77};
 78
 79const makeBreadcrumbs = () => {
 80	return [
 81		{ name: 'Home', item: '/' },
 82		{ name: categoryName, item: slugify(categoryName) },
 83		{
 84			name: parentSection.name,
 85			item: `${slugify(categoryName)}/${slugify(parentSection.name)}`,
 86		},
 87		{
 88			name: name,
 89			item: `${slugify(categoryName)}/${slugify(parentSection.name)}/${slugify(name)}`,
 90		},
 91	];
 92};
 93
 94const makeDescriptionTag = () => {
 95	let desc = `Analysis of ${name}, and other privacy-respecting ${parentSection.name} `;
 96	if (parentSection.services) {
 97		desc += `Compare ${parentSection.services.map((s: Service) => s.name).join(' vs ')} more apps. `;
 98	}
 99	if (parentSection.alternativeTo && parentSection.alternativeTo.length > 0) {
100		desc += `The best secure encrypted alternatives to ${parentSection.alternativeTo.join(', ')}. `;
101	}
102	desc += 'All this, and many more free and awesome tools and software.';
103	return desc;
104};
105
106const filterServices = () => {
107	return parentSection.services.filter((s: Service) => s.name !== name);
108};
109
110export async function getStaticPaths() {
111	const pages = await fetchData().then((data) => {
112		const results: Array<Props> = [];
113		if (!data || !data.categories) return results;
114		(data as AwesomePrivacy).categories.forEach((category) => {
115			category.sections.forEach((section) => {
116				const services = (section.services || []).map((service) => {
117					return {
118						slug: `${slugify(category.name)}/${slugify(section.name)}/${slugify(service.name)}`,
119						parentSection: section,
120						categoryName: category.name,
121						...service,
122					};
123				});
124				results.push(...services);
125			});
126		});
127		return results;
128	});
129
130	return pages.map((props: Props) => {
131		return { params: { listing: props.slug }, props };
132	});
133}
134
135const makePaginationLinks = () => {
136	const allServices = parentSection.services || [];
137	const index = allServices.findIndex((item) => item.name === name);
138	const previousItem = index > 0 ? allServices[index - 1].name : null;
139	const nextItem =
140		index < allServices.length - 1 ? allServices[index + 1].name : null;
141	return { previous: previousItem, next: nextItem };
142};
143
144const { previous, next } = makePaginationLinks();
145
146const ignoredSites = ['github.com', 'wikipedia.'];
147
148const githubData = github ? await fetchGitHubStats(github) : null;
149const securityData = github ? await fetchSecurityReport(github) : null;
150const hasSecurityData =
151	!!securityData &&
152	((securityData.scorecard.available &&
153		securityData.scorecard.checks.length > 0) ||
154		securityData.advisories.count > 0);
155const privacyData = tosdrId ? await fetchTosdrPrivacy(tosdrId) : null;
156const iosData = iosApp ? await fetchIosInfo(iosApp) : null;
157const androidData = androidApp ? await fetchAndroidInfo(androidApp) : null;
158const plexusData = androidApp ? await fetchPlexusInfo(androidApp) : null;
159const discordData = discordInvite
160	? await fetchDiscordInfo(discordInvite)
161	: null;
162const redditData = subreddit ? await fetchRedditInfo(subreddit) : null;
163const dockerData = await fetchDockerData(name);
164const websiteData =
165	url && !ignoredSites.some((s) => url.includes(s))
166		? await fetchWebsiteInfo(url)
167		: null;
168
169const serviceHistory = await fetchChangelog().then(({ entries }) => {
170	const isMatch = (c: { name: string; category: string; section: string }) =>
171		c.name === name &&
172		c.category === categoryName &&
173		c.section === parentSection.name;
174	const isHere = (m: {
175		name: string;
176		to: { category: string; section: string };
177	}) =>
178		m.name === name &&
179		m.to.category === categoryName &&
180		m.to.section === parentSection.name;
181	const results: Array<{
182		date: string;
183		type: 'added' | 'removed' | 'modified' | 'moved' | 'renamed';
184		fields?: string[];
185		from?: { category: string; section: string };
186		previousName?: string;
187		pr?: import('@utils/fetch-changelog').ChangelogPr | null;
188	}> = [];
189	for (const e of entries) {
190		const s = e.changes?.services;
191		const added = (s?.added || []).find(isMatch);
192		const removed = (s?.removed || []).find(isMatch);
193		const modified = (s?.modified || []).find(isMatch);
194		const moved = (s?.moved || []).find(isHere);
195		const renamed = (s?.renamed || []).find(isHere);
196		if (added) results.push({ date: e.date, type: 'added', pr: e.pr });
197		else if (removed) results.push({ date: e.date, type: 'removed', pr: e.pr });
198		else if (modified)
199			results.push({
200				date: e.date,
201				type: 'modified',
202				fields: modified.fields,
203				pr: e.pr,
204			});
205		else if (renamed)
206			results.push({
207				date: e.date,
208				type: 'renamed',
209				previousName: renamed.previousName,
210				from: renamed.from,
211				pr: e.pr,
212			});
213		else if (moved)
214			results.push({ date: e.date, type: 'moved', from: moved.from, pr: e.pr });
215	}
216	return results;
217});
218
219const findPrivacyPolicyLink = () => {
220	if (!privacyData) return null;
221	const docs = privacyData?.parameters?.documents;
222	if (docs) {
223		const pp = (docs || []).find((doc) =>
224			doc.name.toLowerCase().includes('privacy policy'),
225		);
226		if (pp) return pp.url;
227	}
228	return `https://tosdr.org/en/service/${tosdrId}`;
229};
230
231const privacyPolicyLink = findPrivacyPolicyLink();
232
233const catSlug = slugify(categoryName);
234const secSlug = slugify(parentSection.name);
235
236const getApiEndpoint = () => {
237	return `${apiBase}/v1/services/${serviceSlug(name)}`;
238};
239
240const makeSoftwareSchema = () => {
241	const operatingSystem = [
242		iosApp && 'iOS',
243		androidApp && 'Android',
244		url && 'Web',
245	].filter(Boolean);
246	const plainDescription = (description || '')
247		.replace(/\[([^\]]+)\]\([^)]+\)/g, '$1')
248		.replace(/[*_`~]/g, '')
249		.trim();
250	const codeRepository = github
251		? `https://github.com/${github}`
252		: codeberg
253			? codebergUrl(codeberg)
254			: git || null;
255	return {
256		'@context': 'https://schema.org',
257		'@type': 'SoftwareApplication',
258		name,
259		description: plainDescription || makeDescriptionTag(),
260		url,
261		applicationCategory: parentSection.name,
262		...(operatingSystem.length && {
263			operatingSystem: operatingSystem.join(', '),
264		}),
265		...(codeRepository && { codeRepository }),
266	};
267};
268---
269
270<Layout
271	title={makePageTitle()}
272	keywords={makeKeyWordTag()}
273	description={makeDescriptionTag()}
274	breadcrumbs={makeBreadcrumbs()}
275	customSchemaJson={makeSoftwareSchema()}
276>
277	<main>
278		<ListingHero
279			service={Astro.props}
280			parentSection={parentSection}
281			categoryName={categoryName}
282			privacyPolicyLink={privacyPolicyLink}
283		/>
284		{
285			privacyData && privacyData.parameters?.points?.length > 0 && (
286				<section>
287					<h2>{name} Privacy Policy</h2>
288					<PrivacyPolicyDetails privacyData={privacyData} />
289				</section>
290			)
291		}
292		{
293			github && githubData && (
294				<section class="github-wrap">
295					<h2>{name} Source Code</h2>
296					<GitHubDetailedInfo gitHubData={githubData} repo={github} />
297				</section>
298			)
299		}
300		{
301			hasSecurityData && securityData && (
302				<section>
303					<h2>{name} Security</h2>
304					<SecurityDetailedInfo security={securityData} />
305				</section>
306			)
307		}
308		{
309			websiteData && (
310				<section>
311					<h2>{name} Website</h2>
312					<WebsiteDetailedInfo url={url} websiteInfo={websiteData} />
313				</section>
314			)
315		}
316		{
317			((androidData && !androidData.error) || plexusData) && (
318				<section>
319					<h2>{name} Android App</h2>
320					<AndroidAppDetailedInfo
321						androidData={androidData}
322						plexusData={plexusData}
323					/>
324				</section>
325			)
326		}
327		{
328			iosData &&
329				typeof iosData === 'object' &&
330				Object.keys(iosData).length > 0 && (
331					<section>
332						<h2>{name} iOS App</h2>
333						<IosAppDetailedInfo url={url} iosData={iosData} />
334					</section>
335				)
336		}
337		{
338			dockerData && dockerData.found && (
339				<section>
340					<h2>{name} Docker</h2>
341					<DockerDetailedInfo docker={dockerData} />
342				</section>
343			)
344		}
345		{
346			(discordData || redditData) && (
347				<section>
348					<h2>{name} Socials</h2>
349					<div class="social-wrap">
350						{discordData && <DiscordDetailedInfo discordData={discordData} />}
351						{redditData && <RedditDetailedInfo redditData={redditData} />}
352					</div>
353				</section>
354			)
355		}
356
357		<section>
358			<h2>{name} Reviews</h2>
359			<Comments client:visible />
360		</section>
361
362		<section>
363			<h2>More {parentSection.name}</h2>
364			<ServiceList
365				services={filterServices()}
366				subHeading={true}
367				noGitHubMetrics={true}
368				buttonLink={`/${catSlug}/${secSlug}`}
369				categoryName={categoryName}
370				sectionName={parentSection.name}
371			/>
372		</section>
373		<section>
374			<h2>About the Data: {name}</h2>
375			<DataActions
376				client:load
377				categoryName={categoryName}
378				sectionName={parentSection.name}
379				serviceName={name}
380				history={serviceHistory}
381			/>
382			<h3>API</h3>
383			<p>
384				You can access {name}'s data programmatically via our API. Simply make a <code
385					>GET</code
386				> request to:
387			</p>
388			<pre><a href={getApiEndpoint()}><code>{getApiEndpoint()}</code></a></pre>
389			<p>
390				The REST API is free, no-auth and CORS-enabled. To learn more, view the <a
391					href={`${apiBase}/docs`}>API Docs</a
392				> or read the <a href="/about#api">API Usage Guide</a>.
393			</p>
394		</section>
395
396		<section>
397			<h2>Share {name}</h2>
398			<p>
399				Help your friends compare {parentSection.name}, and pick
400				privacy-respecting software and services.<br />
401				Share {name} and Awesome Privacy with your network!
402				<div>
403					<SocialShare
404						url={`${site}/${catSlug}/${secSlug}/${slugify(name)} `}
405						title={`Checkout ${name}! \n`}
406						description={`Compare #${name} and other privacy-respecting ${parentSection.name} at ` +
407							`Awesome-Privacy.xyz, the free and open source list of private software alternatives. ` +
408							`#privacy #opensource #awesomeprivacy by @Lissy_Sykes`}
409					/>
410				</div>
411			</p>
412		</section>
413
414		<div class="pagination-navigation">
415			{
416				previous ? (
417					<Button url={`/${catSlug}/${secSlug}/${slugify(previous)}`}>
418						<span>← Previous</span>
419						<p>{previous}</p>
420					</Button>
421				) : (
422					<p class="nothing" />
423				)
424			}
425			<a href={`/${catSlug}/${secSlug}`} class="go-to-category">
426				View {parentSection.name} ({(parentSection.services || []).length})
427			</a>
428			{
429				next && (
430					<Button url={`/${catSlug}/${secSlug}/${slugify(next)}`}>
431						<span>Next →</span>
432						<p>{next}</p>
433					</Button>
434				)
435			}
436		</div>
437	</main>
438</Layout>
439
440<style lang="scss">
441	main {
442		margin: var(--space-lg) auto;
443		padding: var(--space-md);
444		width: var(--width-container);
445		max-width: var(--width-container-max);
446		position: relative;
447		@media (max-width: 768px) {
448			max-width: 95%;
449			padding: var(--space-sm);
450			margin: 0 auto;
451		}
452	}
453
454	section {
455		margin: var(--space-md) 0 var(--space-2xl) 0;
456		padding: var(--space-md);
457		min-height: 8rem;
458		position: relative;
459		border: var(--border-heavy);
460		box-shadow: var(--shadow-lg);
461		background: var(--accent-fg);
462	}
463
464	p {
465		margin: var(--space-xs) 0 var(--space-sm) 0;
466	}
467
468	h2 {
469		font-size: var(--text-3xl);
470		margin: -2rem 0 var(--space-md) -2rem;
471		box-shadow: var(--shadow-lg);
472		background: var(--accent);
473		color: var(--accent-fg);
474		width: fit-content;
475		padding: var(--space-xs) var(--space-sm);
476		@media (max-width: 768px) {
477			margin: -2rem auto var(--space-lg) auto;
478		}
479	}
480
481	h3 {
482		font-size: var(--text-lg);
483		margin-bottom: 0;
484	}
485
486	pre a {
487		text-decoration: none;
488		color: var(--foreground);
489		code {
490			background: var(--code-bg);
491			padding: 0.2rem 0.4rem;
492			border-radius: var(--curve-sm);
493			font-family: var(--font-code);
494			font-size: var(--text-sm);
495			@media (max-width: 768px) {
496				white-space: break-spaces;
497			}
498		}
499	}
500
501	.social-wrap {
502		display: flex;
503		gap: var(--space-md);
504		flex-wrap: wrap;
505		justify-content: space-between;
506	}
507</style>